package com.nobradovic83.pygsto.core.spring;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class ApplicationContextProviderSingleton implements
		ApplicationContextProvider {

	private static ApplicationContext context;
	
	public ApplicationContext createContext() {
		AbstractApplicationContext context = new ClassPathXmlApplicationContext(
				getContextLocations());
		context.registerShutdownHook();
		return context;
	}

	public ApplicationContext getContext() {
		if (context == null) context = createContext();
		return context;
	}

	public String[] getContextLocations() {
		String[] contextLocations = {
				"META-INF/com/nobradovic83/pygsto/core/spring/context.xml",
				"META-INF/com/nobradovic83/pygsto/domainmodel/context.xml",
				"META-INF/com/nobradovic83/pygsto/core/hsqldb/context.xml",
				"META-INF/com/nobradovic83/pygsto/core/hibernate/context.xml",
				"META-INF/com/nobradovic83/pygsto/service/context.xml"
				
		};
		return contextLocations;
	}

}
